<template>
  <el-dialog
    :title="dialogParam.title"
    :visible.sync="dialogParam.visible"
    :width="dialogParam.width"
  >
    <el-form
      ref="applyForm"
      :rules="rules"
      :model="applyForm"
      label-width="100px"
    >
      <el-form-item label="审批处理:" prop="status" v-if="isRadio">
        <el-radio-group v-model="applyForm.status">
          <el-radio label="0">通过</el-radio>
          <el-radio label="1">不通过</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="请填写原因:" prop="remark">
        <el-input type="textarea" v-model="applyForm.remark" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer text-center">
      <!-- <el-button @click="dialogVisible = false">取 消</el-button> -->
      <el-button type="primary" @click="apply('applyForm')">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { mapGetters } from 'vuex'
export default {
  props:{
    isRadio:{
      type:Boolean,
      default:()=>true
    }
  },
  data() {
    return {
      applyForm: {
        status: '0',
        remark: '',
      },
      rules: {
        status: [
          {
            required: true,
            message: '请选择',
            trigger: ['blur', 'change'],
          },
        ],
        remark: [
          {
            required: true,
            message: '请输入',
            trigger: ['blur', 'change'],
          },
        ],
      },
    }
  },
  computed: {
    ...mapGetters(['dialogParam']),
  },
  watch: {
    dialogParam: {
      deep: true,
      immediate: true,
      handler(val) {
        if (!val) {
            console.log('ssss',val)
            this.$refs['applyForm'].resetFields();
          this.applyForm = {
            status: '0',
            noSuccessDesc: '',
          }
        }
      },
    },
  },
  methods: {
    apply(formName) {
      this.$refs[formName].validate(async (valid) => {
        if (valid) {
          this.$emit('apply-dialog', this.applyForm)
        } else {
          return false
        }
      })
    },
  },
}
</script>

<style lang="scss" scoped>
</style>